﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Fadd.IO.Consoles;
using Fadd.Messaging;
using Xunit;

namespace Fadd.Test.Console
{
    public class Win32
    {
        [DllImport("kernel32.dll")]
        public static extern Boolean AllocConsole();
        [DllImport("kernel32.dll")]
        public static extern Boolean FreeConsole();
    }

    public class TestStandardConsole
    {
        private StandardConsole _console;
        private Command _command;
        private IMessageBroker _broker;

        public TestStandardConsole()
        {
            Win32.AllocConsole();
            _console = new StandardConsole(_broker);
            _console.Start();
        }

        [Fact]
        public void Test()
        {
            _console.WriteLine("Hello world");

            //this test is unfortunally manual since 
            // console already have been redirected.
            global::System.Console.ReadLine();

            global::System.Console.ReadLine();
        }

        public void Publish(IMessage message)
        {
            _command = message as Command;
        }
    }
}
